<?php
class RegistroForm extends BaseForm
{	
	
    
    public function configure()
    {
        parent::configure();
 
        $this->setWidgets(array(
	    'email'     => new sfWidgetFormInputText(array('label' => 'Email')),
	    'nombre'     => new sfWidgetFormInputText(array('label' => 'Nombre')),
	    'apellidos'     => new sfWidgetFormInputText(array('label' => 'Apellidos')),
	    'password'  => new sfWidgetFormInputPassword(array('label' => 'Contraseña')),
            'password2' => new sfWidgetFormInputPassword(array('label' => 'Confirmar')),
	    
	));
 
	$this->setValidators(array(
            'email'        => new sfValidatorEmail(array('required'=>true), array('required'=> "El email es obligatorio")),
            'nombre'  => new sfValidatorString(array('required'=>true), array('required'=> "El nombre es obligatorio")),
            'apellidos'  => new sfValidatorString(array('required'=>true), array('required'=> "Los apellidos son obligatorios")),
            'password'  => new sfValidatorString(array('required'=>true), array('required'=> "La contraseña es obligatoria")),
            'password2' => new sfValidatorString(array('required'=>true), array('required'=> "La contraseña es obligatoria")),
	));
 
	$this->widgetSchema->setNameFormat('registro[%s]');
        $this->widgetSchema->setFormFormatterName('list');
        
 $this->validatorSchema->setPreValidator(new sfValidatorAnd(array(
                 new sfValidatorDoctrineUnique(array('model' => 'Usuario', 'column' => array('email')), array('invalid'=> "Este email ya está en uso"))

     
 )));
        
        
        $this->validatorSchema->setPostValidator(new sfValidatorAnd(array(
            new sfValidatorSchemaCompare('password2', sfValidatorSchemaCompare::EQUAL, 'password', array('throw_global_error' => true), array('invalid' => "Las dos contraseñas no coinciden")),
       //     new sfValidatorDoctrineUnique(array('model' => 'Usuario', 'column' => array('email')), array('invalid'=> "Este email ya está en uso"))
             new sfValidatorDoctrineUnique(array('model' => 'Usuario', 'column' => array('email')))
        )));
     
    }
}
